load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix")
load("//bazel/mkosi:mkosi_image.bzl", "mkosi_image")

mkosi_image(
    name = "initrd",
    srcs = [
        "mkosi.postinst",
    ],
    outs = [
        "image",
        "image.cpio.zst",
    ],
    extra_trees = [
        ":skeleton",
        "//image:sysroot_tar",
        "//image:cryptsetup_closure",
        "//disk-mapper/cmd:disk-mapper-package.tar",
    ],
    local_mirror = ["@mkosi_rpms//:repo"],
    mkosi_conf = "mkosi.conf",
    tags = [
        "manual",
        "no-cache",
    ],
    visibility = ["//visibility:public"],
)

pkg_files(
    name = "skeleton_files",
    srcs = glob(["mkosi.skeleton/**"]),
    attributes = pkg_attributes(mode = "0555"),
    strip_prefix = strip_prefix.from_pkg("mkosi.skeleton"),
)

pkg_tar(
    name = "skeleton",
    srcs = [":skeleton_files"],
)
